<template>
  <div class="mod-menu">
    <el-form :inline="true">
      <el-form-item>
        <el-button v-if="isAuth('sys:menu:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item>
    </el-form>

    <div style="margin-left:7%;margin-right:1%">
      <el-row>
        <el-col :span="11" v-for="(item) in dataList" :key="item.id" class="lightgreen-box">
          <el-card class="box-card" shadow="hover">

            <div slot="header" class="clearfix">
              <span class="span1">{{item.approvalStyleStr}}</span>
              <el-button v-if="isAuth('sys:process:approval:update')" type="text" size="small"
                @click="addOrUpdateHandle(item.approvalStyle)" style="float: right; padding: 0px 3px 0px 0px;">修改</el-button>
              <el-button v-if="isAuth('sys:process:approval:delete')" type="text" size="small"
                @click="deleteHandle(item.approvalStyle)" style="float: right; padding: 0px 9px 0px 0px;">删除</el-button>
            </div>

            <el-steps align-center>
              <el-step v-for="processApproval in item.processApprovalList" :key="processApproval.approvalStyleStr"
                :title="processApproval.approvalDeptStr" :description="processApproval.approvalRoleStr" status="wait"></el-step>
            </el-steps>

          </el-card>
        </el-col>
      </el-row>
    </div>

    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './module/process-approval-add-or-update'
  export default {
    data() {
      return {
        dataList: [],
        dataListLoading: false,
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    activated() {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList() {
        this.$http({
          url: this.$http.adornUrl('/sys/process/approval/list'),
          method: 'post'
        }).then(({ data }) => {
          this.dataList = data
        })
      },
      // 新增 / 修改
      addOrUpdateHandle(approvalStyle) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(approvalStyle)
        })
      },
      // 删除
      deleteHandle(approvalStyle) {
        this.$confirm(`确定删除指定流程?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl(`/sys/process/approval/delete`),
            method: 'post',
            data: approvalStyle
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        }).catch(() => { })
      }
    }
  }
</script>

<style>
  .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }

  .clearfix:after {
    clear: both
  }

  .box-card {
    width: 480px;
    height: 200px;
  }

  .lightgreen-box {
      height: 220px;
    }

  .span1 {
    font-size: 16px;
    font-weight: 800;
  }
</style>
